package logic

import (
	"beego_background_framework/models"
	"beego_background_framework/utils"
	"strings"
	"github.com/astaxie/beego/context"
)

//session相关逻辑

//获取用户的权限id
func GetSessionAuth(ctx *context.Context) []string {
	adminUser := ctx.Input.Session("admin_user")
	var ruleIds []string
	for _,adminGroup := range adminUser.(*models.AdminUser).AdminGroup{
		//判断是否是超级管理员
		if strings.Contains(adminGroup.Rules,"*"){
			return []string{"*"}
		}
		tmp := strings.Split(adminGroup.Rules,",")
		ruleIds = append(ruleIds,tmp...)
	}
	ruleIds = utils.RemoveDuplicateElement(ruleIds)
	return ruleIds
}